package com.msmall.base.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.msmall.base.pager.MatchType;
import com.msmall.base.pager.PaginationSupport;


@SuppressWarnings("unchecked")
public interface BaseDao  <T, PK extends Serializable>{
	
    /**
     * Generic method to get an object based on class and identifier. An
     * ObjectRetrievalFailureException Runtime Exception is thrown if
     * nothing is found.
     *
     * @param id the identifier (primary key) of the object to get
     * @return a populated object
     * @see org.springframework.orm.ObjectRetrievalFailureException
     */
    T get(PK id);
    Object get(Class clazz, Serializable id);

    /**
     * Find a list of records by using a named query
     * @param queryName query name of the named query
     * @param queryParams a map of the query names and the values
     * @return a list of the records found
     */
    List<T> findByNamedQuery(String queryName, Map<String, Object> queryParams);
    
	/**
     * Generic method used to get all objects of a particular type. This
     * is the same as lookup up all rows in a table.
     * @return List of populated objects
     */
    List<T> getAll();
    List getAll(Class clazz);
    
    /**
     * Generic method to save an object - handles both update and insert.
     * @param object the object to save
     * @return the persisted object
     */
    T save(T object);
    public Object saveObject(Object obj);
    /**
     * Generic method to delete an object based on class and id
     * @param id the identifier (primary key) of the object to remove
     */
    void remove(PK id);
    void remove(Class clazz, Serializable id);
    public void remove(Object obj);
	public void removeAll(Collection entities);
	
    /**
     * Checks for existence of an object of type T using the id arg.
     * @param id the id of the entity
     * @return - true if it exists, false if it doesn't
     */
    boolean exists(PK id);
    boolean exists(Class clazz, Serializable id);
    public boolean contains(Object obj);
    
	public List getByProperty(Class clazz, String propertyName, MatchType matchType, String propertyValue);
	public List getByProperty(Class clazz, String[] propertyNames, MatchType[] matchTypes, String[] propertyValues);
    /**
     * 如果设置了queryString 则order by 需要在 queryString中写好
     */
    void getPagination(PaginationSupport page);
}
